import { Core } from "@/comm/Core";
import { URL_LOGIN_TWITTER } from "@/comm/api";
import { get } from "@/comm/request";
import { toast } from "@/components/toast/toast";
import { useAccount } from "@/stores/account";
import { useUser } from "@/stores/user";
import { computed, onMounted, watch } from "vue";

// const HOST = "https://alpha.chainingview.io";
const HOST = import.meta.env.VITE_URL_CALLBACK;
export const useLock = function (timer: number = 300) {
    const account = useAccount();
    const user = useUser();
    let timerId: any;
    const unlock = computed(() => {
        return account.canLook;
    });

    onMounted(() => {
        initLock()
    });

    watch(
        () => user.info,
        val => {
            if (val) {
                clearInterval(timerId)
                account.changeCanLook(true);
            }
        }
    );
    function initLock() {
        setTimeout(() => {
            console.log('查看是否显示锁！！！！！！！！！！！！！！！！！！', !user.info)
            if (!user.info) {
                // setInterval(() => {
                //     account.changeCanLook(true);
                //     setTimeout(() => {
                //         account.changeCanLook(false);
                //     }, 300);
                // }, 4000);
                account.changeCanLook(false);
            }
        }, timer);
    }
    //暂时关闭锁
    function closeLock() {
        const lockInterval = () => {
            if (!user.info) {
                account.changeCanLook(false);
            }
        }
        if (timerId) {
            clearInterval(timerId)
        }
        account.changeCanLook(true);
        timerId = setInterval(() => {
            lockInterval()
        }, timer)
    }
    return { unlock, closeLock };
};
